﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Book_of_Shadow_Script
{
    public enum FilterType
    {
        Table=1,
        WQSGAddress,
        PointerAddress
    }

    public abstract class TextFilter
    {
        FilterType ft;
        public FilterType ShowFilter { get { return ft; } }
        public static TextFilter GetFilter(FilterType ft)
        {
            switch (ft)
            {
                case FilterType.Table: return new TableFilter();
                case FilterType.WQSGAddress: return new WQSGAddressFilter();
                case FilterType.PointerAddress: return new PointerAddressFilter();
            }
            throw new Exception("Invaild filter type");
        }
        public TextFilter(FilterType ft)
        {
            this.ft=ft;
        }
        public abstract String filting(String s);
    }
    class TableFilter : TextFilter
    {
        public TableFilter()
            : base(FilterType.Table)
        { }
        public override string filting(string s)
        {
            if (s.Trim() == String.Empty) return String.Empty;
            Char ch;
            int p1;
            p1 = s.IndexOf('=');
            if (p1 + 1 < s.Length)
                ch = s[p1 + 1];
            else
                throw new IllegalFormatException(p1);
            return new string(ch, 1);
        }
    }
    class WQSGAddressFilter : TextFilter
    {
        public WQSGAddressFilter()
            : base(FilterType.WQSGAddress)
        { }
        public override string filting(string s)
        {
            if (s.Trim() == String.Empty) return String.Empty;
            TextFormat_WQSG tb = new TextFormat_WQSG(s);
            return tb.String;
        }
    }
    class PointerAddressFilter : TextFilter
    {
        public PointerAddressFilter()
            : base(FilterType.PointerAddress)
        { }
        public override String filting(String s)
        {
            if (s.Length <= 4) return String.Empty;
            Char ch = s[0];
            if (ch != '原' && ch != '翻' && ch != '润')
            {
                return String.Empty;
            }
            else
            {
                return s.Substring(4);
            }
        }
    }
}
